﻿// owner 蒋家伟

#include "ElementBaseCompoent.h"

// jsdk
#include "Dbg_Warn_Define.h"
#include "ObjectReflectDefine.h"

using namespace jsdk;

OBJECT_REFLECT_DEFINE(jsdk, ElementBaseCompoent) :
    m_opBasicInfomation(ElementBasicInfomation::create()),
    m_pOwnerDoc(nullptr)
{
}

jsdk::OwnerPtr<jsdk::ElementBaseCompoent> jsdk::ElementBaseCompoent::create()
{
    return NEW_AS_OWNERPTR(jsdk::ElementBaseCompoent);
}

const jsdk::IDocument* jsdk::ElementBaseCompoent::getDocument() const
{
    return getpOwnerDoc__();
}

jsdk::IDocument* jsdk::ElementBaseCompoent::getDocument()
{
    return getpOwnerDocFW__();
}

jsdk::ElementId jsdk::ElementBaseCompoent::getElementId() const
{
    const jsdk::IElementBasicInfomation* pBasicInfomation = getBasicInfomation();
    DBG_WARN_AND_RETURN_UNLESS(pBasicInfomation, ElementId::s_InvalidId, L"当前对象没有对象基本信息", L"蒋家伟", L"2023-12-18");
    return pBasicInfomation->getElementId();
}

void jsdk::ElementBaseCompoent::setTypeUid(const UniqueId& typeUid)
{
    jsdk::ElementBasicInfomation* pBasicInfomation = getBasicInfomationImp();
    DBG_WARN_AND_RETURN_VOID_UNLESS(pBasicInfomation, L"当前对象没有对象基本信息", L"蒋家伟", L"2023-12-18");
    pBasicInfomation->setTypeUid(typeUid);
}

void jsdk::ElementBaseCompoent::setIsTemporary(bool isTemp)
{
    jsdk::ElementBasicInfomation* pBasicInfomation = getBasicInfomationImp();
    DBG_WARN_AND_RETURN_VOID_UNLESS(pBasicInfomation, L"当前对象没有对象基本信息", L"蒋家伟", L"2023-12-18");
    pBasicInfomation->setIsTemporary(isTemp);
}

void jsdk::ElementBaseCompoent::setDocument(IDocument* pDoc)
{
    setpOwnerDoc__(pDoc);
}

void jsdk::ElementBaseCompoent::setElementId(const ElementId& elementId)
{
    jsdk::ElementBasicInfomation* pBasicInfomation = getBasicInfomationImp();
    DBG_WARN_AND_RETURN_VOID_UNLESS(pBasicInfomation, L"当前对象没有对象基本信息", L"蒋家伟", L"2023-12-18");
    pBasicInfomation->setElementId(elementId);
}

void jsdk::ElementBaseCompoent::setComponentOwnerElement(IElement* pElement)
{
    // 1、basicInfo
    jsdk::ElementBasicInfomation* pBasicInfomation = getBasicInfomationImp();
    DBG_WARN_AND_RETURN_VOID_UNLESS(pBasicInfomation, L"当前对象没有对象基本信息", L"蒋家伟", L"2023-12-18");
    pBasicInfomation->setOwnerElement(pElement);
}

jsdk::IElementBasicInfomation* jsdk::ElementBaseCompoent::getBasicInfomation()
{
    return getBasicInfomationImp();;
}

const jsdk::IElementBasicInfomation* jsdk::ElementBaseCompoent::getBasicInfomation() const
{
    return getBasicInfomationImp();
}

const jsdk::ElementBasicInfomation* jsdk::ElementBaseCompoent::getBasicInfomationImp() const
{
    return getopBasicInfomation__().get();
}

jsdk::ElementBasicInfomation* jsdk::ElementBaseCompoent::getBasicInfomationImp()
{
    return getopBasicInfomationFW__().get();
}
